package cn.com.nes.site.entity.em.crm.opportunity;

import cn.com.nes.common.exception.NoSuchEnumException;
import cn.com.nes.site.entity.em.IEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 申报类别 枚举
 *  值域对应 t_param 表 param_type=326
 */
@Slf4j
public enum DeclareCategoryEnum implements IEnum<Integer> {

    NEW(0, "新增户"),
    LOST(1, "遗留户"),
    UPDATE_DEVICE(2, "设备更新"),
    ;

    private Integer key;

    private String value;

    DeclareCategoryEnum(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    @Override
    public Integer getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    public static DeclareCategoryEnum getEnum(String key) {
        Map<String, DeclareCategoryEnum> map = new HashMap<>();
        for (DeclareCategoryEnum declareCategoryEnum : values()) {
            map.put(String.valueOf(declareCategoryEnum.getKey()), declareCategoryEnum);
        }
        if (!map.containsKey(key)) {
            throw new NoSuchEnumException("未匹配的申报类别");
        }
        return map.get(String.valueOf(key));
    }

    public static String enumConvertKeyToValue(String key) {
        String val = "";
        try {
            val = getEnum(key).getValue();
        } catch (NoSuchEnumException e) {
            log.warn("{}, convert key to value error, key:[{}], cause:[{}]", e.getStackTrace()[0].getFileName(), key, e.getMessage());
        }
        return val;
    }
}
